import Vue from 'vue'
//这里仅示范npm安装方式的引入，其它方式引入请看最上面【安装】部分
import Router from 'uni-simple-router'
import store from '@/store'
import ROUTES from './ROUTES'; // 确保引入了 ROUTES

Vue.use(Router)
//初始化
const router = new Router({
	encodeURI: false,
	h5: {
		paramsToQuery: true,
	},
	routes: ROUTES //路由表
});

//全局路由前置守卫
router.beforeEach((to, from, next) => {
	console.log(to.path)
	// next({ name: 'index/index' });
	const isLoggedIn = store.getters.isLoggedIn
	if (to.meta.requiresAuth && !isLoggedIn) {
		// 如果页面需要登录且用户未登录，则跳转到登录页面
		next({ name: 'index/login' });
		
	}else {
		next()
	}
})
// 全局路由后置守卫
router.afterEach((to, from) => {})
export default router;